﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace qf_cms.admin
{
	public partial class sort_item : System.Web.UI.Page
	{
		LogicLayer mgr = new LogicLayer();
		protected string pid = "", type = "", tip = "";

		protected void Page_Load(object sender, EventArgs e)
		{
			pid = Request.QueryString["pid"] + "";
			type = Request.QueryString["type"] + "";

			if (IsPostBack)
			{
				System.Collections.Hashtable hash = new System.Collections.Hashtable();
				string key = string.Empty;
				for (int i = 0; i < Request.Form.Count; i++)
				{
					key = Request.Form.GetKey(i);
					if (key.StartsWith("txt_"))
					{
						hash.Add(key.Replace("txt_", ""), Request.Form[i]);
					}
				}
				if (mgr.SortItem(hash, type))
					Response.Redirect("columnGeneral.aspx?id=" + pid);
				else
					tip = "保存失败!";
			}

		}

		protected void WriteTableData()
		{
			if (type == "column")
			{
				List<CMS_Columns> colList = mgr.ListColumns(pid);
				if (colList == null)
					return;

				foreach (CMS_Columns col in colList)
				{
					Response.Write("<tr>");

					Response.Write("<td nowrap>");
					Response.Write(col.ColumnName);
					Response.Write("</td>");

					Response.Write("<td >");
					string eleName = "txt_" + col.ColumnID;
					Response.Write("<input type=\"text\" id=\"" + eleName  + "\" name=\"" + eleName + "\" value=\"" + col.SequenceNo +"\" />");
					Response.Write("</td>");

					Response.Write("</tr>");
				}
			}
			else
			{
				List<CMS_Article> artList = mgr.ListArticles(pid);
				if (artList == null)
					return;

				foreach (CMS_Article art in artList)
				{
					Response.Write("<tr>");

					Response.Write("<td nowrap>");
					Response.Write(art.ArticleTitle);
					Response.Write("</td>");

					Response.Write("<td >");
					string eleName = "txt_" + art.ArticleID;
					Response.Write("<input type=\"text\" id=\"" + eleName + "\" name=\"" + eleName + "\" value=\"" + art.SequenceNo + "\" />");
					Response.Write("</td>");

					Response.Write("</tr>");
				}
			}
		}
	}
}